//
//  HomePageMoreView.m
//  ShowYork
//
//  Created by hxh on 2020/10/1.
//  Copyright © 2020 hxh. All rights reserved.
//

#define itemH 60
#define itemLine 8

typedef void(^doneBlock)(NSInteger index);

#import "HomePageFollowMoreView.h"

@interface HomePageFollowMoreView ()
@property (nonatomic,strong)UIView *containView;
@property (nonatomic,strong)UILabel *followMainTitleLb;
@property (nonatomic,strong)UILabel *followSubTitleLb;
@property (nonatomic,strong)UIButton *followBtn;
@property (nonatomic,strong)UIButton *feedbackBtn;
@property (nonatomic,strong)UIButton *cancelBtn;
@property (nonatomic,strong)UIView *line;
@property (nonatomic,strong)UIView *sep;
@property (nonatomic,copy)doneBlock done;
@end

@implementation HomePageFollowMoreView

- (instancetype)initWithCompleteBlock:(void (^)(NSInteger index))completeBlock{
    if (self = [super init]) {
        [self setUI];
        if (completeBlock) {
            self.done = ^(NSInteger index) {
                completeBlock(index);
            };
        }
    }
    return self;
}
- (void)setUI{
    self.frame = CGRectMake(0, 0, kScreenW, kScreenH);
    self.backgroundColor = RGBA(0, 0, 0, 0.4);
    
    self.containView = [[UIView alloc]init];
    self.containView.backgroundColor = [UIColor whiteColor];
    [self addSubview:self.containView];
    
    [self.containView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(itemH *3 + itemLine + GK_SAVEAREA_BTM);
        make.bottom.mas_equalTo(self).offset(itemH * 3 + itemLine + GK_SAVEAREA_BTM);
        make.left.right.equalTo(self);
    }];
    
    self.followBtn = [[UIButton alloc]init];
    [self.followBtn addTarget:self action:@selector(followMethod) forControlEvents:UIControlEventTouchUpInside];
    [self.containView addSubview:self.followBtn];
    
    [self.followBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.containView);
        make.size.mas_equalTo(CGSizeMake(kScreenW * 0.6, 60));
        make.centerX.equalTo(self.containView);
    }];
    
    self.feedbackBtn = [[UIButton alloc]init];
    [self.feedbackBtn setTitle:@"投诉" forState:UIControlStateNormal];
    [self.feedbackBtn setTitleColor:RGBA(51, 51, 51, 1) forState:UIControlStateNormal];
    self.feedbackBtn.titleLabel.font = font(18);
    [self.feedbackBtn addTarget:self action:@selector(feedbackMethod) forControlEvents:UIControlEventTouchUpInside];
    [self.containView addSubview:self.feedbackBtn];
    
    [self.feedbackBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.followBtn.mas_bottom);
        make.size.mas_equalTo(CGSizeMake(kScreenW * 0.6, 60));
        make.centerX.equalTo(self.containView);
    }];
    self.line = [[UIView alloc]init];
    self.line.backgroundColor = RGBA(248, 248, 248, 1);
    [self.containView addSubview:self.line];
    [self.line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.feedbackBtn.mas_bottom);
        make.left.right.equalTo(self.containView);
        make.height.mas_equalTo(8);
    }];

    self.cancelBtn = [[UIButton alloc]init];
    [self.cancelBtn setTitle:@"取消" forState:UIControlStateNormal];
    [self.cancelBtn setTitleColor:RGBA(51, 51, 51, 1) forState:UIControlStateNormal];
    self.cancelBtn.titleLabel.font = font(18);
    [self.cancelBtn addTarget:self action:@selector(dismiss) forControlEvents:UIControlEventTouchUpInside];
    [self.containView addSubview:self.cancelBtn];
    [self.cancelBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.line.mas_bottom);
        make.size.mas_equalTo(CGSizeMake(kScreenW * 0.6, 60));
        make.centerX.equalTo(self.containView);
    }];
    
    self.followMainTitleLb = [[UILabel alloc]init];
    self.followMainTitleLb.text = @"取消关注";
    self.followMainTitleLb.textColor = RGBA(51, 51, 51, 1);
    self.followMainTitleLb.font = font(18);
    [self.containView addSubview:self.followMainTitleLb];
    [self.followMainTitleLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.containView).offset(12);
        make.centerX.equalTo(self.containView);
    }];
    
    self.followSubTitleLb = [[UILabel alloc]init];
    self.followSubTitleLb.text = @"不再关注TA";
    self.followSubTitleLb.textColor = C153;
    self.followSubTitleLb.font = font(10);
    [self.containView addSubview:self.followSubTitleLb];
    [self.followSubTitleLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.containView);
        make.top.equalTo(self.followMainTitleLb.mas_bottom).offset(2);
    }];
    
    self.sep = [[UIView alloc]init];
    self.sep.backgroundColor = RGBA(230, 230, 230, 1);
    [self.containView addSubview:self.sep];
    
    [self.sep mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.containView).offset(16);
        make.right.equalTo(self.containView).offset(-16);
        make.height.mas_equalTo(0.5);
        make.top.equalTo(self.followBtn.mas_bottom);
    }];
        
    
  
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(dismiss)];
    [self addGestureRecognizer:tap];
}

- (void)drawRect:(CGRect)rect{
    [super drawRect:rect];
    UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:self.containView.bounds byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight cornerRadii:CGSizeMake(15, 15)];
    CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
    maskLayer.frame = self.containView.bounds;
    maskLayer.path = maskPath.CGPath;
    self.containView.layer.mask = maskLayer;
    
}

- (void)show{
    [[UIApplication sharedApplication].keyWindow addSubview:self];
    
    [self layoutIfNeeded];
      
    [self.containView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self);
    }];
    [UIView animateWithDuration:0.25 animations:^{
        [self layoutIfNeeded];
    }];
}
- (void)dismiss{
    [self.containView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self).offset(itemH * 3 + itemLine + GK_SAVEAREA_BTM);
    }];
    [UIView animateWithDuration:0.25 animations:^{
        [self layoutIfNeeded];
    } completion:^(BOOL finished) {
        if (finished) {
            [self removeFromSuperview];
        }
    }];
}

- (void)followMethod{
    if (self.done) {
        self.done(1);
    }
    [self dismiss];
}

- (void)feedbackMethod{
    if (self.done) {
        self.done(2);
    }
    [self dismiss];
}


@end
